package org.ptkparty.client.ui;

import org.ptkparty.shared.model.PtkEnum.STATE;

import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.user.client.ui.ListBox;

public class ChampionshipStateListBox extends ListBox implements LeafValueEditor<STATE> {

	public ChampionshipStateListBox() {
		addItem("Publique", STATE.PUBLIC.toString());
		addItem("Privé", STATE.PRIVATE.toString());
		addItem("Fermé", STATE.CLOSED.toString());
	}

	@Override
	public void setValue(STATE value) {
		if (value != null) {
			for (int i = 0; i < getItemCount(); i++) {
				if (getValue(i).equals(value.toString())) {
					setSelectedIndex(i);
					break;
				}
			}
		}
	}

	@Override
	public STATE getValue() {
		if (getSelectedIndex() != -1) {
			return STATE.valueOf(getValue(getSelectedIndex()));
		} else {
			return null;
		}
	}

}
